package com.example.zuoye;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;
public class BaseAdapterActivity extends AppCompatActivity {
    private ListView lv_yq;
    private List<Yq> list = new ArrayList<Yq>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_base_adapter);
        lv_yq = findViewById(R.id.lv_yq);

        Yq yq1 =new Yq("11","胡豆",10);
        Yq yq2 =new Yq("21","甘蓝菜",90);
        Yq yq3 =new Yq("31","小白菜",80);
        Yq yq4 =new Yq("41","花椰菜",70);
        Yq yq5 =new Yq("51","香菜",60);
        Yq yq6 =new Yq("61","南瓜",50);
        Yq yq7 =new Yq("71","软糖",40);
        Yq yq8 =new Yq("81","红糖",30);
        Yq yq9 =new Yq("91","喜糖",20);
        Yq yq10 =new Yq("13","果糖",1);

        list.add(yq1); list.add(yq2);
        list.add(yq3); list.add(yq4);
        list.add(yq5); list.add(yq6);
        list.add(yq7); list.add(yq8);
        list.add(yq9); list.add(yq10);

        YqAdapter yqAdapter = new YqAdapter();
        lv_yq.setAdapter(yqAdapter);
    }

    private class YqAdapter extends BaseAdapter {
        @Override
        public int getCount() {
            return list.size();
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        public View getView(int i, View view, ViewGroup viewGroup) {
            View view1 = View.inflate(BaseAdapterActivity.
                    this, R.layout.activity_item, null);
            Yq yq = list.get(i);
            TextView yqid=view1.findViewById(R.id.yqid);
            yqid.setText(yq.getYqid());

            TextView yqname=view1.findViewById(R.id.yqname);
            yqname.setText(yq.getYqname());

            TextView pricy=view1.findViewById(R.id.pricy);
            pricy.setText(yq.getPrice()+"");
            return view1;
        }
    }
}